<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2017/4/27
 * Time: 15:00
 */

namespace app\front\controller;


class Personal extends Home
{
    public function index(){
        $user = db("account_registration")->where("id",$this->userId)->find();
        $this->assign("record",$user);
        return $this->fetch();
    }

    public function cert(){
        $user = db("account_registration")->where("id",$this->userId)->find();
        $this->assign("record",$user);
        return $this->fetch();
    }
    public function changepass(){
        if(IS_POST){
            $userpass = input("userpass");
            $res = db("account_registration")->where("id",$this->userId)->update(['userpass'=>inge_encryption_pwd($userpass,"Rake")]);
            if($res){
                return $this->ret->setCode(0)->setMsg('修改密码成功')->toJson();
            }else{
                return $this->ret->setCode(1)->setMsg("修改密码失败，请重试")->toJson();
            }
        }else{
            return $this->fetch();
        }
    }

    public function edit(){
        if(IS_POST){
            $post = input();
            $res = db("account_registration")->where("id",$this->userId)->update($post);
            if($res){
                return $this->ret->setCode(0)->setMsg("修改成功")->toJson();
            }else{
                return $this->ret->setCode(1)->setMsg("修改失败，请重试")->toJson();
            }
        }else{
            return $this->fetch();
        }
    }


}